import 'package:t3_foundation/t3_foundation.dart';
import 'package:t3_data_service/biz_data_source/map/poi/lat_lng.dart';

class T3AbsorbedEndPoint {
  final int index;
  final String name;
  final LatLng? coordinate;

  T3AbsorbedEndPoint({
    required this.index,
    required this.name,
    this.coordinate,
  });

  Map<String, dynamic> toJson() {
    return {
      'index' : index,
      'name' : name,
      'coordinate' : coordinate,
    };
  }

  bool get isValid {
    return index != -1 && name.isNotEmpty;
  }

  factory T3AbsorbedEndPoint.fromJson(Map<dynamic, dynamic> json) {
    return T3AbsorbedEndPoint(
      index: IntUtils.dynamicToInt(json['index'], -1),
      name: StringUtils.dynamicToString(json['name']) ?? '',
      coordinate: LatLng.fromJson(json['coordinate']),
    );
  }
}